package de.kieselbach.javafx.builder.factory

import javafx.scene.layout.BorderPane
import de.kieselbach.javafx.builder.proxy.Position
import de.kieselbach.javafx.builder.proxy.ProxyNode

/*
 * Copyright 2012 by procar informatik AG,
 * Eschenweg 7, 64331 Weiterstadt, Germany
 * All rights reserved.
 */
class BorderPaneBuilderFactory extends AbstractBuilderFactory {

    @Override
    String getName() {

        return 'borderPane'
    }

    @Override
    Class getNodeClass() {

        return BorderPane.class
    }

    @Override
    void setParent(Object parent, Object child) {

    }

    @Override
    void nodeCompleted(Object parent, Object child) {

        if(child instanceof ProxyNode) {
            if(child.node) {
                switch(child.position) {
                    default:
                        parent.center = child.node
                        break

                    case Position.CENTER:
                        parent.center = child.node
                        break

                    case Position.TOP:
                        parent.top = child.node
                        break

                    case Position.LEFT:
                        parent.left = child.node
                        break

                    case Position.BOTTOM:
                        parent.bottom = child.node
                        break

                    case Position.RIGHT:
                        parent.right = child.node
                        break
                }

                if(child.margin) {
                    parent.setMargin(child.node, child.margin);
                }
                if(child.alignment) {
                    parent.setAlignment(child.node, child.alignment);
                }
            }
        }
        else {
            parent.center = child
        }
    }

    @Override
    def createNode(Object name, Map attributes, Object value) {

        def pane = new BorderPane()

        if(attributes != null) {
            attributes.each() {key, val ->
                pane[key] = val
            }
        }

        pane
    }
}
